package com.yly.doctorapp.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yly.doctorapp.R;
import com.yly.doctorapp.bean.OrederBean;
import com.zhcx.zhcxlibrary.utils.DateUtils;

import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class OrderAdapter extends BaseAdapter {
    private Context mContext;
    private List<OrederBean> orederBeanList;

    public OrderAdapter(Context mContext, List<OrederBean> orederBeanList) {
        this.mContext = mContext;
        this.orederBeanList = orederBeanList;
    }

    @Override
    public int getCount() {
        return orederBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return orederBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
        if (convertView == null) {
            view = View.inflate(mContext, R.layout.layout_orderitem, null);
        } else {
            view = convertView;
        }
        if (null != orederBeanList && orederBeanList.size() > 0){
            ViewHolder holder = new ViewHolder(view);
            holder.tvOrderno.setText(orederBeanList.get(position).getMyOrderId());
            setOrderType(orederBeanList.get(position).getFlag(), holder);
            holder.tvOrdermoney.setText("¥" + orederBeanList.get(position).getLatestPrice());
            holder.tvOrderstatus.setText(orederBeanList.get(position).getSendStatus());
            holder.tvOrdertime.setText(DateUtils.dateyyyyMMdd(new Date(orederBeanList.get(position).getCreatedTime())));
        }
        return view;
    }

    private void setOrderType(int type, ViewHolder holder){
        switch (type){
            case -1:
                holder.tvOrdertype.setText("全部");
                break;
            case 0:
                holder.tvOrdertype.setText("普通产品订单");
                break;
            case 1:
                holder.tvOrdertype.setText("中医知识产品订单");
                break;
            case 2:
                holder.tvOrdertype.setText("医生推荐产品订单");
                break;
            case 3:
                holder.tvOrdertype.setText("咨询费订单");
                break;
            case 4:
                holder.tvOrdertype.setText("处方订单");
                break;
        }
    }

    static class ViewHolder {
        @BindView(R.id.tv_orderno)
        TextView tvOrderno;
        @BindView(R.id.tv_ordertype)
        TextView tvOrdertype;
        @BindView(R.id.tv_orderstatus)
        TextView tvOrderstatus;
        @BindView(R.id.tv_ordertime)
        TextView tvOrdertime;
        @BindView(R.id.tv_ordermoney)
        TextView tvOrdermoney;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
